// var url = "https://mxj.zv100.net/api/";
var url = "https://service.zv100.net/api/";
// var url = "https://dev.lizhongwen.cn/api/";
var mturl = "https://openflow.mtlab.meitu.com/";
var urllId = "https://service.zv100.net/api/convert/idCut";
// var urllId = "https://dev.lizhongwen.cn/api/convert/idCut";

function request(urll, postData, doSuccess, doFail, doComplete) {
     let pages = getCurrentPages()
    let currentPaper = pages[pages.length-1];
    var token = wx.getStorageSync('AccToken') || '';
    var uid = wx.getStorageSync('uid') || '';
    var printId = wx.getStorageSync('machineQrCode') || '';
    if (urll == 'Login/weChat') {
        token = '';
    }
    postData.ver = '2.3.4';
    wx.request({
        url: url + urll,
        data: postData,
        method: 'POST',
        header: {
            'content-type': 'application/json',
            'uid': uid,
            'terminal': 3,
            'token': token,
            'machineQrCode': printId
        },
        success: function (res) {
            if (typeof doSuccess == "function") {
                if (res.data.code == 401) {
                    if (currentPaper.selectComponent("#loading")) {
                        currentPaper.selectComponent("#loading").hideLoadingCus()
                    } else {
                        wx.hideLoading()
                    }
                    wx.removeStorageSync('AccToken') //登录失效
                     wx.removeStorageSync("uid");
                    if(urll!='config/config'&&urll!='home/homeTopBtn'&&urll!='home/scrollAdList'&&urll!='home/serviceItem'&&urll!='home/dialogAdList'){
                        wx.navigateTo({
                            url: '/pages/my/login/login',
                        })
                    }
                } else if (res.data.code == 402) {
                    if (currentPaper.selectComponent("#loading")) {
                        currentPaper.selectComponent("#loading").hideLoadingCus()
                    } else {
                        wx.hideLoading()
                    }
                     if(urll!='config/config'&&urll!='home/homeTopBtn'&&urll!='home/scrollAdList'&&urll!='home/serviceItem'&&urll!='home/dialogAdList'){
                        toast(res.data.msg) //账号禁用
                    }
                } else {
                    doSuccess(res) //通过
                }
            }
        },
        fail: function (res) {
            if (currentPaper.selectComponent("#loading")) {
                currentPaper.selectComponent("#loading").hideLoadingCus()
            } else {
                wx.hideLoading()
            }
            if (typeof doFail == "function") {
                doFail(res);
            }
        },
        complete: function () {
            if (typeof doComplete == "function") {
                doComplete();
            }
        }
    });
}

function requestMT(urll, postData, doSuccess, doFail, doComplete) {
     let pages = getCurrentPages()
    let currentPaper = pages[pages.length-1];
    wx.request({
        url: urll,
        data: postData,
        method: 'POST',
        header: {
            'content-type': 'application/json'
        },
        success: function (res) {
            if (currentPaper.selectComponent("#loading")) {
                currentPaper.selectComponent("#loading").hideLoadingCus()
            } else {
                wx.hideLoading()
            }
            if (typeof doSuccess == "function") {
                doSuccess(res);
            }
        },
        fail: function (res) {
            if (currentPaper.selectComponent("#loading")) {
                currentPaper.selectComponent("#loading").hideLoadingCus()
            } else {
                wx.hideLoading()
            }
            if (typeof doFail == "function") {
                doFail(res);
            }
        },
        complete: function (err) {
            if (typeof doComplete == "function") {
                doComplete();
            }
        }
    });
}

function get(urll, postData, doSuccess, doFail, doComplete) {
     let pages = getCurrentPages()
    let currentPaper = pages[pages.length-1];
    wx.request({
        url: urll,
        data: postData,
        method: 'GET',
        header: {
            'content-type': 'application/x-www-form-urlencoded',
            'token': wx.getStorageSync('AccToken') ? wx.getStorageSync('AccToken') : '',
            'cookie': wx.getStorageSync('Set-Cookie') ? wx.getStorageSync('Set-Cookie') : ''
        },
        success: function (res) {
            if (currentPaper.selectComponent("#loading")) {
                currentPaper.selectComponent("#loading").hideLoadingCus()
            } else {
                wx.hideLoading()
            }
            if (typeof doSuccess == "function") {
                doSuccess(res);
            }
        },
        fail: function (res) {
            if (currentPaper.selectComponent("#loading")) {
                currentPaper.selectComponent("#loading").hideLoadingCus()
            } else {
                wx.hideLoading()
            }
            if (typeof doFail == "function") {
                doFail(res);
            }
        },
        complete: function () {
            if (typeof doComplete == "function") {
                doComplete();
            }
        }
    });
}

function is_mobile(v) {
    var reg = /^0{0,1}(13[0-9]|18[0-9]|17[0-9]|14[0-9]|15[0-9]|16[0-9]|19[0-9])[0-9]{8}$/;
    return reg.test(v);
}



function html_decode(str) {
    var s = "";
    if (str.length == 0) return "";
    s = str.replace(/&amp;/g, "&");
    s = s.replace(/&lt;/g, "<");
    s = s.replace(/&gt;/g, ">");
    s = s.replace(/&nbsp;/g, " ");
    s = s.replace(/&#39;/g, "\'");
    s = s.replace(/&quot;/g, "\"");
    s = s.replace(/<br\/>/g, "\n");
    return s;
}

function alert(title) {
    wx.showModal({
        title: '提示',
        content: title,
        showCancel: false,
        success(res) { }
    })
}

function is_define(value) {
    if (value == null || value == "" || value == "undefined" || value == undefined || value == "null" || value == "(null)" || value == 'NULL' || typeof (value) == 'undefined') {
        return false;
    } else {
        value = value + "";
        value = value.replace(/\s/g, "");
        if (value == "") {
            return false;
        }
        return true;
    }
}

function toast(title, duration) {
    var time = is_define(duration) ? duration : 2000
    wx.showToast({
        title: title,
        icon: 'none',
        duration: time
    })
}

function mtuploadfile(path, doSuccess) {
     let pages = getCurrentPages()
    let currentPaper = pages[pages.length-1];
    wx.uploadFile({
        url: mturl + 'meitudata/upload',
        filePath: path,
        name: 'file',
        timeout: 180000,
        formData: {

        },
        header: {
            'content-type': 'application/x-www-form-urlencoded'
        },
        success: function (res) {
            if (currentPaper.selectComponent("#loading")) {
                currentPaper.selectComponent("#loading").hideLoadingCus()
            } else {
                wx.hideLoading()
            }
            if (typeof doSuccess == "function") {
                doSuccess(res);
            }
        },
        fail: function (res) {
            if (currentPaper.selectComponent("#loading")) {
                currentPaper.selectComponent("#loading").hideLoadingCus()
            } else {
                wx.hideLoading()
            }
            wx.stopPullDownRefresh()
            if (typeof doFail == "function") {
                doFail(res);
            }
        },
        complete: function (err) {
            if (typeof doComplete == "function") {
                doComplete();
            }
        }
    })
}
//获取sheet url方式
function getSheetByUrl(name, fileUrl, doSuccess) {
     let pages = getCurrentPages()
    let currentPaper = pages[pages.length-1];
    var token = wx.getStorageSync('AccToken') ? wx.getStorageSync('AccToken') : '';
    var uid = wx.getStorageSync('uid') ? wx.getStorageSync('uid') : '';
    var printId = wx.getStorageSync('machineQrCode') || '';
    wx.request({
        url: url + 'convert/getExcelSheet',
        data: {
            'name': name,
            'url': fileUrl,
            'version': '2.3.4'
        },
        method: 'POST',
        header: {
            'machineQrCode': printId,
            'content-type': 'application/x-www-form-urlencoded',
            'uid': uid,
            'terminal': 3,
            'token': token,
        },
        success: function (res) {
            if (typeof doSuccess == "function") {
                if (res.data.code == 401) {
                    if (currentPaper.selectComponent("#loading")) {
                        currentPaper.selectComponent("#loading").hideLoadingCus()
                    } else {
                        wx.hideLoading()
                    }
                    wx.removeStorageSync('AccToken') //登录失效
                     wx.removeStorageSync("uid");
                    wx.navigateTo({
                        url: '/pages/my/login/login',
                    })
                } else if (res.data.code == 402) {
                    if (currentPaper.selectComponent("#loading")) {
                        currentPaper.selectComponent("#loading").hideLoadingCus()
                    } else {
                        wx.hideLoading()
                    }
                    toast(res.data.msg) //账号禁用
                } else if (res.data.code == 200) {
                    doSuccess(res) //通过
                } else {
                    if (currentPaper.selectComponent("#loading")) {
                        currentPaper.selectComponent("#loading").hideLoadingCus()
                    } else {
                        wx.hideLoading()
                    }
                    toast(res.data.msg)
                }
            }
        },
        fail: function (res) {
            if (currentPaper.selectComponent("#loading")) {
                currentPaper.selectComponent("#loading").hideLoadingCus()
            } else {
                wx.hideLoading()
            }
            if (typeof doFail == "function") {
                if (currentPaper.selectComponent("#loading")) {
                    currentPaper.selectComponent("#loading").hideLoadingCus()
                } else {
                    wx.hideLoading()
                }
                doFail(res);
            }
        },
        complete: function () {
            if (typeof doComplete == "function") {
                doComplete();
            }
        }
    });
}
// 获取sheet
function uploadfileExcel(path, name, doSuccess) {
    let pages = getCurrentPages()
    let currentPaper = pages[pages.length - 1];
    var token = wx.getStorageSync('AccToken') ? wx.getStorageSync('AccToken') : '';
    var uid = wx.getStorageSync('uid') ? wx.getStorageSync('uid') : '';
    var printId = wx.getStorageSync('machineQrCode') || '';
    wx.uploadFile({
        url: url + 'convert/getExcelSheet',
        filePath: path,
        name: 'file',
        timeout: 180000,
        formData: {
            'name': name,
            'version': '2.3.4'
        },
        header: {
            'content-type': 'application/x-www-form-urlencoded',
            'uid': uid,
            'terminal': 3,
            'token': token,
            'machineQrCode': printId
        },
        success: function (res) {
            var data = JSON.parse(res.data)
            if (data.code == 401) {
                if (currentPaper.selectComponent("#loading")) {
                    currentPaper.selectComponent("#loading").hideLoadingCus()
                } else {
                    wx.hideLoading()
                }
                wx.removeStorageSync('AccToken') //登录失效
                 wx.removeStorageSync("uid");
                wx.navigateTo({
                    url: '/pages/my/login/login',
                })
            } else if (data.code == 402) {
                if (currentPaper.selectComponent("#loading")) {
                    currentPaper.selectComponent("#loading").hideLoadingCus()
                } else {
                    wx.hideLoading()
                }
                toast(data.msg) //账号禁用
            } else if (data.code == 200) {
                if (currentPaper.selectComponent("#loading")) {
                    currentPaper.selectComponent("#loading").hideLoadingCus()
                } else {
                    wx.hideLoading()
                }
                doSuccess(res) //通过
            } else {
                if (currentPaper.selectComponent("#loading")) {
                    currentPaper.selectComponent("#loading").hideLoadingCus()
                } else {
                    wx.hideLoading()
                }
                toast(data.msg)
            }
        },
        fail: function (res) {
            if (currentPaper.selectComponent("#loading")) {
                currentPaper.selectComponent("#loading").hideLoadingCus()
            } else {
                wx.hideLoading()
            }
            wx.stopPullDownRefresh()
            if (typeof doFail == "function") {
                doFail(res);
            }
        },
        complete: function (err) {
            if (typeof doComplete == "function") {
                doComplete();
            }
        }
    })

}
function uploadZip(path, doSuccess) {
    let pages = getCurrentPages()
    let currentPaper = pages[pages.length - 1];
    var token = wx.getStorageSync('AccToken') ? wx.getStorageSync('AccToken') : '';
    var uid = wx.getStorageSync('uid') ? wx.getStorageSync('uid') : '';
    var printId = wx.getStorageSync('machineQrCode') || '';
    wx.uploadFile({
        url: url + 'zip/un',
        filePath: path,
        name: 'file',
        timeout: 180000,
        formData: {
            'password': '',
            'version': '2.3.4'
        },
        header: {
            'content-type': 'application/x-www-form-urlencoded',
            'uid': uid,
            'terminal': 3,
            'token': token,
            'machineQrCode': printId
        },
        success: function (res) {

            var data = JSON.parse(res.data)
            if (data.code == 401) {
                if (currentPaper.selectComponent("#loading")) {
                    currentPaper.selectComponent("#loading").hideLoadingCus()
                } else {
                    wx.hideLoading()
                }
                wx.removeStorageSync('AccToken') //登录失效
                 wx.removeStorageSync("uid");
                wx.navigateTo({
                    url: '/pages/my/login/login',
                })
            } else if (data.code == 402) {
                if (currentPaper.selectComponent("#loading")) {
                    currentPaper.selectComponent("#loading").hideLoadingCus()
                } else {
                    wx.hideLoading()
                }
                toast(res.data.msg) //账号禁用
            } else if (data.code == 200) {
                if (currentPaper.selectComponent("#loading")) {
                    currentPaper.selectComponent("#loading").hideLoadingCus()
                } else {
                    wx.hideLoading()
                }
                doSuccess(res) //通过
            } else if (data.code == -200) {
                if (currentPaper.selectComponent("#loading")) {
                    currentPaper.selectComponent("#loading").hideLoadingCus()
                } else {
                    wx.hideLoading()
                }
                doSuccess(res) //通过
            } else {
                if (currentPaper.selectComponent("#loading")) {
                    currentPaper.selectComponent("#loading").hideLoadingCus()
                } else {
                    wx.hideLoading()
                }
                toast(data.msg)
            }
        },
        fail: function (res) {
            wx.hideLoading()
            wx.stopPullDownRefresh()
            if (currentPaper.selectComponent("#loading")) {
                currentPaper.selectComponent("#loading").hideLoadingCus()
            } else {
                wx.hideLoading()
            }
            if (typeof doFail == "function") {
                doFail(res);
            }
        },
        complete: function (err) {
            if (typeof doComplete == "function") {
                doComplete();
            }
        }
    })
}
function uploadfile(path, name, fileUrl, base64, orientation, doSuccess) {
    let pages = getCurrentPages()
    let currentPaper = pages[pages.length - 1];
    var token = wx.getStorageSync('AccToken') ? wx.getStorageSync('AccToken') : '';
    var uid = wx.getStorageSync('uid') ? wx.getStorageSync('uid') : '';
    var printId = wx.getStorageSync('machineQrCode') || '';
    if (is_define(path)) {
        wx.uploadFile({
            url: url + 'upload/printFile',
            filePath: path,
            name: 'file',
            timeout: 180000,
            formData: {
                'orientation': orientation ? orientation : 1,
                'name': name,
                'url': fileUrl,
                'version': '2.3.4',
                'base64': base64
            },
            header: {
                'content-type': 'application/x-www-form-urlencoded',
                'uid': uid,
                'terminal': 3,
                'token': token,
                'machineQrCode': printId
            },
            success: function (res) {
                // currentPaper.selectComponent("#loading").hideLoadingCus()
                if (currentPaper.selectComponent("#loading")) {
                    currentPaper.selectComponent("#loading").hideLoadingCus()
                } else {
                    wx.hideLoading()
                }
                var data = JSON.parse(res.data)
                if (data.code == 401) {
                    wx.hideLoading()
                    wx.removeStorageSync('AccToken') //登录失效
                     wx.removeStorageSync("uid");
                    wx.navigateTo({
                        url: '/pages/my/login/login',
                    })
                } else if (data.code == 402) {
                    wx.hideLoading()
                    toast(res.data.msg) //账号禁用
                } else if (data.code == 200) {
                    wx.hideLoading()
                    doSuccess(res) //通过
                } else {
                    wx.hideLoading()
                    toast(data.msg)
                }
            },
            fail: function (res) {
                wx.stopPullDownRefresh()
                currentPaper.selectComponent("#loading").hideLoadingCus()
                if (typeof doFail == "function") {
                    doFail(res);
                }
            },
            complete: function (err) {
                if (typeof doComplete == "function") {
                    doComplete();
                }
            }
        })
    } else {
        wx.request({
            url: url + 'upload/printFile',
            data: {
                'orientation': orientation ? orientation : '1',
                'name': name,
                'url': fileUrl,
                'version': '2.3.4',
                'base64': base64
            },
            method: 'POST',
            header: {
                'machineQrCode': printId,
                'content-type': 'application/x-www-form-urlencoded',
                'uid': uid,
                'terminal': 3,
                'token': token,
            },
            success: function (res) {
                if (typeof doSuccess == "function") {
                    if (res.data.code == 401) {
                        if (currentPaper.selectComponent("#loading")) {
                            currentPaper.selectComponent("#loading").hideLoadingCus()
                        } else {
                            wx.hideLoading()
                        }
                        wx.removeStorageSync('AccToken') //登录失效
                         wx.removeStorageSync("uid");
                        wx.navigateTo({
                            url: '/pages/my/login/login',
                        })
                    } else if (res.data.code == 402) {
                        if (currentPaper.selectComponent("#loading")) {
                            currentPaper.selectComponent("#loading").hideLoadingCus()
                        } else {
                            wx.hideLoading()
                        }
                        toast(res.data.msg) //账号禁用
                    } else if (res.data.code == 200) {
                        wx.hideLoading()
                        doSuccess(res) //通过
                    } else {
                        if (currentPaper.selectComponent("#loading")) {
                            currentPaper.selectComponent("#loading").hideLoadingCus()
                        } else {
                            wx.hideLoading()
                        }
                        toast(res.data.msg)
                    }
                }
            },
            fail: function (res) {
                if (typeof doFail == "function") {
                    doFail(res);
                }
            },
            complete: function () {
                if (typeof doComplete == "function") {
                    doComplete();
                }
            }
        });
    }
}
//普通文件类接口（包含图片）
function uploadFileMin(path, doSuccess, doFail, doComplete) {
    let pages = getCurrentPages()
    let currentPaper = pages[pages.length - 1];
    var token = wx.getStorageSync('AccToken') ? wx.getStorageSync('AccToken') : '';
    var printId = wx.getStorageSync('machineQrCode') || '';
    var uid = wx.getStorageSync('uid') ? wx.getStorageSync('uid') : '';
    wx.uploadFile({
        url: url + 'upload/uploadFile',
        filePath: path,
        name: 'file',
        timeout: 180000,
        formData: {

        },
        header: {
            'content-type': 'application/x-www-form-urlencoded',
            'uid': uid,
            'terminal': 3,
            'token': token,
            'machineQrCode': printId
        },
        success: function (res) {
            var data = JSON.parse(res.data)
            if (data.code == 401) {
                if (currentPaper.selectComponent("#loading")) {
                    currentPaper.selectComponent("#loading").hideLoadingCus()
                } else {
                    wx.hideLoading()
                }

                wx.removeStorageSync('AccToken') //登录失效
                 wx.removeStorageSync("uid");
                wx.navigateTo({
                    url: '/pages/my/login/login',
                })
            } else if (data.code == 402) {
                if (currentPaper.selectComponent("#loading")) {
                    currentPaper.selectComponent("#loading").hideLoadingCus()
                } else {
                    wx.hideLoading()
                }
                toast(data.msg) //账号禁用
            } else if (data.code == 200) {
                doSuccess(res) //通过
            } else {
                if (currentPaper.selectComponent("#loading")) {
                    currentPaper.selectComponent("#loading").hideLoadingCus()
                } else {
                    wx.hideLoading()
                }
                toast(data.msg)
            }
        },
        fail: function (res) {
            if (currentPaper.selectComponent("#loading")) {
                currentPaper.selectComponent("#loading").hideLoadingCus()
            } else {
                wx.hideLoading()
            }
            wx.stopPullDownRefresh()
            if (typeof doFail == "function") {
                doFail(res);
            }
        },
        complete: function (err) {
            if (typeof doComplete == "function") {
                doComplete();
            }
        }
    })

}
//图像类接口上传
function uploadImg(path, doSuccess, doFail, doComplete) {
    let pages = getCurrentPages()
    let currentPaper = pages[pages.length - 1];
    var token = wx.getStorageSync('AccToken') ? wx.getStorageSync('AccToken') : '';
    var uid = wx.getStorageSync('uid') ? wx.getStorageSync('uid') : '';
    var printId = wx.getStorageSync('machineQrCode') || '';
    wx.uploadFile({
        url: url + 'upload/uploadImage',
        filePath: path,
        name: 'file',
        timeout: 180000,
        formData: {

        },
        header: {
            'content-type': 'application/x-www-form-urlencoded',
            'uid': uid,
            'terminal': 3,
            'token': token,
            'machineQrCode': printId
        },
        success: function (res) {
            var data = JSON.parse(res.data)
            if (data.code == 401) {
                if (currentPaper.selectComponent("#loading")) {
                    currentPaper.selectComponent("#loading").hideLoadingCus()
                } else {
                    wx.hideLoading()
                }
                wx.removeStorageSync('AccToken') //登录失效
                 wx.removeStorageSync("uid");
                wx.navigateTo({
                    url: '/pages/my/login/login',
                })
            } else if (data.code == 402) {
                if (currentPaper.selectComponent("#loading")) {
                    currentPaper.selectComponent("#loading").hideLoadingCus()
                } else {
                    wx.hideLoading()
                }
                currentPaper.selectComponent("#loading").hideLoadingCus()
                toast(data.msg) //账号禁用
            } else if (data.code == 200) {
                wx.hideLoading()
                doSuccess(res) //通过
            } else {
                if (currentPaper.selectComponent("#loading")) {
                    currentPaper.selectComponent("#loading").hideLoadingCus()
                } else {
                    wx.hideLoading()
                }
                toast(data.msg)
            }
        },
        fail: function (res) {
            if (currentPaper.selectComponent("#loading")) {
                currentPaper.selectComponent("#loading").hideLoadingCus()
            } else {
                wx.hideLoading()
            }
            wx.stopPullDownRefresh()
            if (typeof doFail == "function") {
                doFail(res);
            }
        },
        complete: function (err) {
            if (typeof doComplete == "function") {
                doComplete();
            }
        }
    })

}
//身份证抠图
function requestId(path, doSuccess, doFail, doComplete) {
    let pages = getCurrentPages()
    let currentPaper = pages[pages.length - 1];
    var token = wx.getStorageSync('AccToken') ? wx.getStorageSync('AccToken') : '';
    var uid = wx.getStorageSync('uid') ? wx.getStorageSync('uid') : '';
    var printId = wx.getStorageSync('machineQrCode') || '';
    wx.uploadFile({
        url: urllId,
        filePath: path,
        timeout: 180000,
        name: 'file',
        formData: {

        },
        header: {
            'content-type': 'application/x-www-form-urlencoded',
            'uid': uid,
            'terminal': 3,
            'token': token,
            'machineQrCode': printId
        },
        success: function (res) {
            var data = JSON.parse(res.data)
            if (data.code == 401) {
                if (currentPaper.selectComponent("#loading")) {
                    currentPaper.selectComponent("#loading").hideLoadingCus()
                } else {
                    wx.hideLoading()
                }
                wx.removeStorageSync('AccToken') //登录失效
                 wx.removeStorageSync("uid");
                wx.navigateTo({
                    url: '/pages/my/login/login',
                })
            } else if (data.code == 402) {
                if (currentPaper.selectComponent("#loading")) {
                    currentPaper.selectComponent("#loading").hideLoadingCus()
                } else {
                    wx.hideLoading()
                }
                toast(data.msg) //账号禁用
            } else if (data.code == 200) {
                wx.hideLoading()
                doSuccess(res) //通过
            } else {
                if (currentPaper.selectComponent("#loading")) {
                    currentPaper.selectComponent("#loading").hideLoadingCus()
                } else {
                    wx.hideLoading()
                }
                toast(data.msg)
            }
        },
        fail: function (res) {
            if (currentPaper.selectComponent("#loading")) {
                currentPaper.selectComponent("#loading").hideLoadingCus()
            } else {
                wx.hideLoading()
            }
            wx.stopPullDownRefresh()
            if (typeof doFail == "function") {
                doFail(res);
            }
        },
        complete: function (err) {
            if (typeof doComplete == "function") {
                doComplete();
            }
        }
    })
}

function scanuploadfile(urll, path, doSuccess) {
    let pages = getCurrentPages()
    let currentPaper = pages[pages.length - 1];
    var token = wx.getStorageSync('AccToken') ? wx.getStorageSync('AccToken') : '';
    var uid = wx.getStorageSync('uid') ? wx.getStorageSync('uid') : '';
    var printId = wx.getStorageSync('machineQrCode') || '';
    wx.uploadFile({
        url: url + urll,
        filePath: path,
        name: 'file',
        timeout: 180000,
        header: {
            'content-type': 'application/x-www-form-urlencoded',
            'uid': uid,
            'terminal': 3,
            'token': token,
            'machineQrCode': printId
        },
        success: function (res) {
            var data = JSON.parse(res.data)
            if (data.code == 401) {
                if (currentPaper.selectComponent("#loading")) {
                    currentPaper.selectComponent("#loading").hideLoadingCus()
                } else {
                    wx.hideLoading()
                }
                wx.removeStorageSync('AccToken') //登录失效
                 wx.removeStorageSync("uid");
                wx.navigateTo({
                    url: '/pages/my/login/login',
                })
            } else if (data.code == 402) {
                if (currentPaper.selectComponent("#loading")) {
                    currentPaper.selectComponent("#loading").hideLoadingCus()
                } else {
                    wx.hideLoading()
                }
                toast(data.msg) //账号禁用
            } else if (data.code == 200) {
                wx.hideLoading()
                doSuccess(res) //通过
            } else {
                if (currentPaper.selectComponent("#loading")) {
                    currentPaper.selectComponent("#loading").hideLoadingCus()
                } else {
                    wx.hideLoading()
                }
                toast(data.msg)
            }
        },
        fail: function (res) {
            if (currentPaper.selectComponent("#loading")) {
                currentPaper.selectComponent("#loading").hideLoadingCus()
            } else {
                wx.hideLoading()
            }
            wx.stopPullDownRefresh()
            if (typeof doFail == "function") {
                doFail(res);
            }
        },
        complete: function (err) {
            if (typeof doComplete == "function") {
                doComplete();
            }
        }
    })
}

function returnFloat(num) {
    num = num.toString(); // 转成字符串类型  如能确定类型 这步可省去
    if (num.indexOf(".") != -1) {
        let newVal = num.split(".");
        if (newVal[1].length == 1) {
            newVal = newVal.join(".");
            newVal += "0";
            num = newVal;
        }
    } else {
        num += ".00";
    }

    return num;
}

function getIntersection(str1, str2) {
    let retArr = [];
    let arr1 = str1.split(",");
    let arr2 = str2.split(",");
    arr1.map(item => {
        arr2.map(item2 => {
            if (item2 == item) {
                retArr.push(item);
            }
        });
    });
    return retArr;
}

function base64_encode(str) {
    //下面是64个基本的编码
    var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
    var out, i, len;
    var c1, c2, c3;
    len = str.length;
    i = 0;
    out = "";
    while (i < len) {
        c1 = str.charCodeAt(i++) & 0xff;
        if (i == len) {
            out += base64EncodeChars.charAt(c1 >> 2);
            out += base64EncodeChars.charAt((c1 & 0x3) << 4);
            out += "==";
            break;
        }
        c2 = str.charCodeAt(i++);
        if (i == len) {
            out += base64EncodeChars.charAt(c1 >> 2);
            out += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4));
            out += base64EncodeChars.charAt((c2 & 0xF) << 2);
            out += "=";
            break;
        }
        c3 = str.charCodeAt(i++);
        out += base64EncodeChars.charAt(c1 >> 2);
        out += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4));
        out += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >> 6));
        out += base64EncodeChars.charAt(c3 & 0x3F);
    }
    return out;
}
/*
 *  base64编码(编码，配合encodeURIComponent使用)
 *  @parm : str 传入的字符串
 */
function utf16to8(str) {
    var out, i, len, c;
    out = "";
    len = str.length;
    for (i = 0; i < len; i++) {
        c = str.charCodeAt(i);
        if ((c >= 0x0001) && (c <= 0x007F)) {
            out += str.charAt(i);
        } else if (c > 0x07FF) {
            out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
            out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
            out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
        } else {
            out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
            out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
        }
    }
    return out;
}

/*
  *  base64解码(配合decodeURIComponent使用)
  *  @parm : input 传入的字符串
  *  使用：
        1、引入util.js(路径更改) :const util  = require('../../utils/util.js');
        2、util.base64_decode('YmFzZTY0IOe8lueggQ==');
 */
function base64_decode(input) {
    var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var output = "";
    var chr1, chr2, chr3;
    var enc1, enc2, enc3, enc4;
    var i = 0;
    input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
    while (i < input.length) {
        enc1 = base64EncodeChars.indexOf(input.charAt(i++));
        enc2 = base64EncodeChars.indexOf(input.charAt(i++));
        enc3 = base64EncodeChars.indexOf(input.charAt(i++));
        enc4 = base64EncodeChars.indexOf(input.charAt(i++));
        chr1 = (enc1 << 2) | (enc2 >> 4);
        chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
        chr3 = ((enc3 & 3) << 6) | enc4;
        output = output + String.fromCharCode(chr1);
        if (enc3 != 64) {
            output = output + String.fromCharCode(chr2);
        }
        if (enc4 != 64) {
            output = output + String.fromCharCode(chr3);
        }
    }
    return utf8_decode(output);
}

/*
 *  utf-8解码
 *  @parm : utftext 传入的字符串
 */
function utf8_decode(utftext) {
    var string = '';
    let i = 0;
    let c = 0;
    let c1 = 0;
    let c2 = 0;
    while (i < utftext.length) {
        c = utftext.charCodeAt(i);
        if (c < 128) {
            string += String.fromCharCode(c);
            i++;
        } else if ((c > 191) && (c < 224)) {
            c1 = utftext.charCodeAt(i + 1);
            string += String.fromCharCode(((c & 31) << 6) | (c1 & 63));
            i += 2;
        } else {
            c1 = utftext.charCodeAt(i + 1);
            c2 = utftext.charCodeAt(i + 2);
            string += String.fromCharCode(((c & 15) << 12) | ((c1 & 63) << 6) | (c2 & 63));
            i += 3;
        }
    }
    return string;
}

/*
    * base64编码函数封装
    * @parm: str(传入要编成base64的内容)
    * 使用：
        1、引入util.js(路径更改) :const util  = require('../../utils/util.js');
        2、util.baseEncode('base64 编码');
*/
function baseEncode(str) {
    return base64_encode(utf16to8(str));
}
/*
    * base64解码函数封装
    * @parm: str(传入要解为正常字体)
    * 使用：
        1、引入util.js(路径更改) :const util  = require('../../utils/util.js');
        2、util.baseDecode(util.baseEncode('base64 编码'))
*/
function baseDecode(str) {
    return base64_decode(str);
} // 抛出函数使用
function isEmptyObject(obj) {
    for (let key in obj) {
        if (obj.hasOwnProperty(key)) {
            return false
        }
    }
    return true
}
module.exports = {
    isEmptyObject: isEmptyObject,
    baseEncode: baseEncode,
    baseDecode: baseDecode,
    requestMT: requestMT,
    uploadfile: uploadfile,
    mtuploadfile: mtuploadfile,
    get: get,
    request: request,
    is_define: is_define,
    alert: alert,
    is_mobile: is_mobile,
    toast: toast,
    html_decode: html_decode,
    requestId: requestId,
    scanuploadfile: scanuploadfile,
    returnFloat: returnFloat,
    uploadImg: uploadImg,
    uploadfileExcel: uploadfileExcel,
    getIntersection: getIntersection,
    uploadFileMin: uploadFileMin,
    uploadZip: uploadZip,
    getSheetByUrl: getSheetByUrl
}